var express = require('express');
var router = express.Router();

var ItbCouponModel = require('../../../common/mysql/mapping/ItbCouponModel');
var TgDesignDocModel = require('../../../common/mysql/mapping/TgDesignDocModel');
var ItbTmplStatsModel = require('../../../common/mysql/mapping/ItbTmplStatsModel');
var YjxTmplStatsModel = require('../../../common/mysql/mapping/YjxTmplStats');
var ItbPartnerApplicationModel = require('../../../common/mysql/mapping/ItbPartnerApplicationModel');
var ItbPartnerSaleRankModel = require('../../../common/mysql/mapping/ItbPartnerSaleRankModel');
var ItbExpTrackInfoModel = require('../../../common/mysql/mapping/ItbExpTrackInfoModel');//引入物流Model
var CONFIG = require('../../../common/config');
var CODE = require('../../../common/code');
var async  = require('async');
var moment = require('moment');

var luaUtil = require('./luaUtil');

var cacheManager = require('cache-manager');
var redisStore = require('cache-manager-redis');
var request = require('request');//获取request

/**
 * *******************************************************************
 * 注意:［node_modules/cache-manager-redis/index.js］文件需要添加以下函数
 *
 * self.randomkey = function(cb) {
 *   connect(function(err, conn) {
 *     if(err) {
 *       return cb && cb(err);
 *     }
 *     conn.randomkey(handleResponse(conn, cb));
 *   });
 * };
 * *******************************************************************
 */

// APP抽奖用
//var CouponRedisCache = cacheManager.caching({
//    store: redisStore,
//    host: CONFIG.COUPON_REDIS_SERVER_DOMAIN,
//    port: CONFIG.COUPON_REDIS_SERVER_PORT,
//    auth_pass: CONFIG.COUPON_REDIS_SERVER_PASSWORD,
//    db: CONFIG.COUPON_REDIS_SERVER_DB_NUMBER,
//    ttl: CONFIG.COUPON_REDIS_SERVER_TTL,
//    prefix: CONFIG.COUPON_REDIS_SERVER_PREFIX
//});
//if(typeof CouponRedisCache.store.randomkey === 'function') {
//    CouponRedisCache.randomkey = CouponRedisCache.store.randomkey.bind(CouponRedisCache.store);
//}
//
//// 城市合伙人抽奖用（印品券）
//var Coupon2RedisCache = cacheManager.caching({
//    store: redisStore,
//    host: CONFIG.COUPON2_REDIS_SERVER_DOMAIN,
//    port: CONFIG.COUPON2_REDIS_SERVER_PORT,
//    auth_pass: CONFIG.COUPON2_REDIS_SERVER_PASSWORD,
//    db: CONFIG.COUPON2_REDIS_SERVER_DB_NUMBER,
//    ttl: CONFIG.COUPON2_REDIS_SERVER_TTL,
//    prefix: CONFIG.COUPON2_REDIS_SERVER_PREFIX
//});
//if(typeof Coupon2RedisCache.store.randomkey === 'function') {
//    Coupon2RedisCache.randomkey = Coupon2RedisCache.store.randomkey.bind(Coupon2RedisCache.store);
//}
//// 城市合伙人抽奖用（vip券）
//var Coupon3RedisCache = cacheManager.caching({
//    store: redisStore,
//    host: CONFIG.COUPON3_REDIS_SERVER_DOMAIN,
//    port: CONFIG.COUPON3_REDIS_SERVER_PORT,
//    auth_pass: CONFIG.COUPON3_REDIS_SERVER_PASSWORD,
//    db: CONFIG.COUPON3_REDIS_SERVER_DB_NUMBER,
//    ttl: CONFIG.COUPON3_REDIS_SERVER_TTL,
//    prefix: CONFIG.COUPON3_REDIS_SERVER_PREFIX
//});
//if(typeof Coupon3RedisCache.store.randomkey === 'function') {
//    Coupon3RedisCache.randomkey = Coupon3RedisCache.store.randomkey.bind(Coupon3RedisCache.store);
//}
//
//var COUPON_KEY_PREFIX = 'itb_coupon_key_';


//------------------------------------------------------------------
// 各种优惠券共用
var AllCouponRedisCache = cacheManager.caching({
    store: redisStore,
    host: CONFIG.COUPONS_REDIS_SERVER_DOMAIN,
    port: CONFIG.COUPONS_REDIS_SERVER_PORT,
    auth_pass: CONFIG.COUPONS_REDIS_SERVER_PASSWORD,
    db: CONFIG.COUPONS_REDIS_SERVER_DB_NUMBER,
    ttl: CONFIG.COUPONS_REDIS_SERVER_TTL,
    //prefix: CONFIG.COUPONS_REDIS_SERVER_PREFIX
});
var ALL_COUPON_PREFIX = 'ITB_COUPON_';




//------------------------------------------------------------------
var callFuncUtil = (function () {
    function callFuncUtil() {
    };

    //------------------------------------------------------------------
    // 返回json
    callFuncUtil.ret_func_json = function (success, msg, data, res){
        var obj = {
            success: success,
            msg: msg,
            data: data
        };
        // 返回
        res.set('Content-Type', 'application/json');
        res.json(obj);
    };

    //------------------------------------------------------------------
    // 设置抽奖券缓存池
    // use: 10通用,20APP抽奖用,30合伙人抽奖用[印品],31合伙人抽奖用[VIP会员],40直接发放用
    callFuncUtil.setCouponCache = function(use, maxCnt, flg, add, callback){

        function addToCache(use, couponItems) {
            var ids = [];
            for(var i=0;i<couponItems.length;i++){
                var value = couponItems[i].c_code || '';
                if(value && value.length>0) {
                    //rds.set(key, '0');
                    luaUtil.setCoupon(use, value, function(err, ret){
                        //console.log('Set ['+value+'] Ret: '+ret);
                    });
                    ids.push(couponItems[i].c_id||'0');
                }
            }
            return ids;
        }

        (new ItbCouponModel).getCouponForLuckyDraw(use, maxCnt, function(err, retItems){
            if(err){
                return callback(err, null);
            }

            if(retItems && retItems.length>0){
                //var rds = CouponRedisCache;
                //if(use==30) {
                //    rds = Coupon2RedisCache;
                //} else if(use==31) {
                //    rds = Coupon3RedisCache;
                //}

                if(add==1) {// 直接添加
                    var ids = addToCache(use, retItems);

                    var retData = {cnt:(ids||[]).length};
                    if(flg==1) {
                        retData.ids=ids||[];
                    }
                    return callback(null, retData);

                } else {
                    // 先重置
                    //rds.reset(function(err2, ret2){
                    luaUtil.resetCoupon(use, function(err2, ret2){
                        if(err2){
                            return callback(err2, null);
                        }

                        var ids = addToCache(use, retItems);

                        var retData = {cnt:(ids||[]).length};
                        if(flg==1) {
                            retData.ids=ids||[];
                        }
                        return callback(null, retData);
                    });
                }
            } else {
                return callback('未获取到数据', null);
            }
        });
    };

    // 检查优惠券缓存
    // use: 10通用,20APP抽奖用,30合伙人抽奖用[印品],31合伙人抽奖用[VIP会员],40直接发放用
    callFuncUtil.cntCouponCache = function(use, retKeyFlg, callback){
        //var rds = CouponRedisCache;
        //if(use==30) {
        //    rds = Coupon2RedisCache;
        //} else if(use==31) {
        //    rds = Coupon3RedisCache;
        //}

        var keyPrefix = callFuncUtil.getCouponKeyPrefix(use);

        if(!keyPrefix || keyPrefix.length==0) {
            return callback('参数错误', null);
        }

        var rds = AllCouponRedisCache;

        rds.keys(keyPrefix+'*', function(err, ret){
            if(err){
                return callback(err, null);
            }

            var retData = {cnt:0};

            if(ret && ret.length>0) {
                retData.cnt = ret.length;

                if(retKeyFlg == 1) {
                    retData.keys = [];
                    for(var i=0;i<ret.length;i++){
                        var key = ret[i] || '';
                        retData.keys.push(key);
                    }
                }
            }

            return callback(null, retData);
        });
    };

    //------------------------------------------------------------------
    // 随机抽取优惠码
    // minCnt/maxCnt: 随机数范围
    // use: 10通用,20APP抽奖用,30合伙人抽奖用[印品],31合伙人抽奖用[VIP会员],40直接发放用
    callFuncUtil.getRandomCouponFromCache = function(use, minCnt, maxCnt, callback){
        // 随机选出Cnt个
        var min=Number(minCnt||'0')||0;
        var max=Number(maxCnt||'0')||0;
        if(min<0) min=0;
        if(max<min) max=min;

        //var cnt = Math.floor(Math.random()*(Number(maxCnt||'0')+1));
        var cnt = min+Math.floor(Math.random()*(max-min+1));
        if(cnt<=0) {
            return callback(null, []);
        }

        callFuncUtil.getCouponFromCache(use, cnt, function(err, ret){
            return callback(err, ret);
        });
    };

    // 获取优惠券
    // use: 10通用,20APP抽奖用,30合伙人抽奖用[印品],31合伙人抽奖用[VIP会员],32[logo],40直接发放用
    callFuncUtil.getCouponFromCache = function(use, cnt, callback) {
        //var rds = CouponRedisCache;
        //if(use==30) {
        //    rds = Coupon2RedisCache;
        //} else if(use==31) {
        //    rds = Coupon3RedisCache;
        //}

        var subAsync = [];
        for(var n=0; n<cnt; n++) {
            subAsync.push((function(idx){
                return function(subCallback) {
                    // 随机获取
                    //rds.randomkey(function(err, retKey){
                    //    if(retKey && retKey.length>0) {
                    //        // 删除已获取到的
                    //        rds.del(retKey, function(err2, delCnt){
                    //            if(err2 || delCnt==0) {
                    //                return subCallback(null, '');
                    //            }
                    //            return subCallback(null, retKey);
                    //        });
                    //    } else {
                    //        return subCallback(null, '');
                    //    }
                    //});

                    luaUtil.getCouponRandom(use, function(err, retKey){
                        if(retKey && retKey.length>0) {
                            return subCallback(null, retKey);
                        }
                        return subCallback(null, '');
                    });
                }
            })(n));
        }
        // 串行处理
        async.series(subAsync, function(error, results){
            var retData = [];
            if(results && results.length>0) {
                for(var i=0; i<results.length; i++){
                    if(results[i] && results[i].length>0) {
                        retData.push(results[i]);
                    }
                }
            }

            return callback(error, retData);
        });
    };


    //------------------------------------------------------------------
    // 设置模版应用次数数据
    // radix: 倍数
    // type: 模版类型
    // ids: 逗号连接的模版id
    callFuncUtil.setTmplApplyCnt = function(radix, type, ids, callback){

        (new TgDesignDocModel).getTmplApplyCnt(type, ids, function(err, ret) {
            if(err) {
                return callback(err, null);
            }

            if(!ret || ret.length<=0) {
                return callback('No Data', null);
            }

            var subAsync = [];
            for(var n=0; n<ret.length; n++) {
                subAsync.push((function(idx, info){
                    return function(subCallback) {
                        // check
                        var ent = new ItbTmplStatsModel({
                            tmpl_id: info.tmpl_id,
                            type: info.type,
                            del_flg: 0
                        });
                        ent.findFromDB(function(findErr, findRet){ // 查询所有的内容
                            if(findErr) {
                                return subCallback(null, 'E');
                            }
                            if(findRet && findRet.length>0) {
                                // 更新
                                var data = findRet[0];
                                var updEnt = new ItbTmplStatsModel({
                                    id: data.id,
                                    apply_cnt: info.apply_cnt,
                                    show_apply_cnt: data.show_apply_cnt+(info.apply_cnt-data.apply_cnt),
                                    update_by: 'API_UPD'
                                });
                                updEnt.updateToDB(function(updErr){
                                    if(updErr) {
                                        return subCallback(null, 'E');
                                    }
                                    return subCallback(null, 'U');
                                });

                            } else {
                                var newShowApplyCnt = Number(info.apply_cnt||'0')*radix;
                                if(newShowApplyCnt==0) {
                                    newShowApplyCnt = Math.floor(Math.random()*10+1)*radix;/*基数随机1～10*/
                                }
                                // 新建
                                var insEnt = new ItbTmplStatsModel({
                                    tmpl_id: info.tmpl_id,
                                    type: info.type,
                                    item_id: info.item_id,
                                    apply_cnt: Number(info.apply_cnt||'0'),
                                    show_apply_cnt: newShowApplyCnt,
                                    update_by: 'API_INS'
                                });
                                insEnt.saveToDB(function(insErr, newId){
                                    if(insErr) {
                                        return subCallback(null, 'E');
                                    }
                                    return subCallback(null, 'I');
                                });
                            }
                        });
                    }
                })(n, ret[n]));
            }
            // 串行处理
            async.series(subAsync, function(error, results){
                var retData = {
                    GetCnt: ret.length,
                    InsCnt: 0,
                    UpdCnt: 0,
                    ErrCnt: 0,
                };

                if(results && results.length>0) {
                    for(var i=0; i< results.length; i++) {
                        if(results[i]=='I') {
                            retData.InsCnt += 1;
                        } else if(results[i]=='U') {
                            retData.UpdCnt += 1;
                        } else if(results[i]=='E') {
                            retData.ErrCnt += 1;
                        }
                    }
                }

                return callback(error, retData);
            });
        });
    };

    /**
     *  作者 ：李琦  串行处理 一键秀模板[单页模板、视频模板]应用次数
     *  设置一键秀 模版应用次数
     * @param radix radix: 倍数 默认11  表示实际应用次数的11倍
     * @param type type: 模版类型
     * @param ids ids: 逗号连接的模版id
     * @param callback
     */

    callFuncUtil.setYjxTmplApplyCnt = function(radix, type, ids, callback){

        (new TgDesignDocModel).getYjxTmplApplyCnt(type, ids, function(err, ret) {
            if(err) {
                return callback(err, null);
            }

            if(!ret || ret.length<=0) {
                return callback('No Data', null);
            }

            var subAsync = [];
            for(var n=0; n<ret.length; n++) {
                subAsync.push((function(idx, info){
                    return function(subCallback) {
                        // check
                        var ent = new YjxTmplStatsModel({
                            uni_item_id: info.uni_item_id,
                            del_flg: 0
                        });
                        ent.findFromDB(function(findErr, findRet){
                            if(findErr) {
                                return subCallback(null, 'E');
                            }
                            if(findRet && findRet.length>0) {
                                // 更新
                                var data = findRet[0];
                                var updEnt = new YjxTmplStatsModel({
                                    id: data.id,
                                    apply_cnt: info.apply_cnt,
                                    show_apply_cnt: data.show_apply_cnt+(info.apply_cnt-data.apply_cnt),
                                    update_by: 'add_kris'
                                });
                                updEnt.updateToDB(function(updErr){
                                    if(updErr) {
                                        return subCallback(null, 'E');
                                    }
                                    return subCallback(null, 'U');
                                });

                            } else {
                                var newShowApplyCnt = Number(info.apply_cnt||'0')*radix;
                                if(newShowApplyCnt==0) {
                                    newShowApplyCnt = Math.floor(Math.random()*10+1)*radix;/*基数随机1～10*/
                                }
                                // 新建
                                var insEnt = new YjxTmplStatsModel({
                                    uni_item_id: info.uni_item_id,
                                    apply_cnt: Number(info.apply_cnt||'0'),
                                    show_apply_cnt: newShowApplyCnt,
                                    update_by: 'upd_kris'
                                });
                                insEnt.saveToDB(function(insErr, newId){
                                    if(insErr) {
                                        return subCallback(null, 'E');
                                    }
                                    return subCallback(null, 'I');
                                });
                            }
                        });
                    }
                })(n, ret[n]));
            }
            // 串行处理
            async.series(subAsync, function(error, results){
                var retData = {
                    GetCnt: ret.length,
                    InsCnt: 0,
                    UpdCnt: 0,
                    ErrCnt: 0,
                };

                if(results && results.length>0) {
                    for(var i=0; i< results.length; i++) {
                        if(results[i]=='I') {
                            retData.InsCnt += 1;
                        } else if(results[i]=='U') {
                            retData.UpdCnt += 1;
                        } else if(results[i]=='E') {
                            retData.ErrCnt += 1;
                        }
                    }
                }

                return callback(error, retData);
            });
        });
    };
    // ----------------------------万能的分割线------------------------------------

    //------------------------------------------------------------------
    /* 刷新合伙人月度销售排名信息
     * 参数: y: 年份
     * 参数: m: 月份
     * */
    callFuncUtil.refreshSaleRankInfo = function(callback, y, m){
        var year = Number(y||'0')||0;
        var month = Number(m||'0')||0;
        if(year<2016 || month<1 || month>12) {
            return callback('参数错误',null);
        }

        var userId=-100;// TODO

        //function getFirstDay(yyyy,mm) {
        //    var dt = new Date(yyyy,mm-1,1);// 月份下标从0开始
        //    var mt = moment(dt);
        //    return mt.format('YYYY-MM-DD');
        //}
        //function getLastDay(yyyy,mm) {
        //    var dt = new Date(yyyy,mm,1);// 下个月第一天
        //    var cdt = new Date(dt.getTime()-1000*3600*24);
        //    var mt = moment(cdt);
        //    return mt.format('YYYY-MM-DD');
        //}
        //
        //var stDt = getFirstDay(year, month)+' 00:00:00';
        //var edDt = getLastDay(year, month)+' 23:59:59';

        // 获取存在合伙人的地区(根据申请地区检索)
        (new ItbPartnerApplicationModel).getPartnerExistArea(function(getErr, retAreaInfo){
            if(getErr) {
                return callback(getErr, null);
            }

            if(retAreaInfo && retAreaInfo.length>0) {
                // 循环处理各地区数据
                var subAsync = [];
                for(var n=0; n<retAreaInfo.length; n++) {
                    subAsync.push((function(idx, areaInfo){
                        return function(subCallback) {
                            var rankEnt = new ItbPartnerSaleRankModel;
                            // 删除旧数据
                            rankEnt.delMonthAreaSaleInfo(function(delErr, delRet){
                                if(delErr) {
                                    return subCallback(delErr, null);
                                }

                                // 插入新数据
                                rankEnt.insMonthAreaSaleInfo(function(insErr, insRet){
                                    if(insErr) {
                                        return subCallback(insErr, null);
                                    }

                                    // 更新排名序号
                                    rankEnt.updMonthAreaSaleRankNum(function(updErr, updRet){

                                        return subCallback(null, {id:areaInfo.dist, updCnt:Number(insRet.affectedRows||'0')||0});

                                    }, userId, year, month, areaInfo.prov, areaInfo.city, areaInfo.dist);

                                }, userId, year, month, areaInfo.prov, areaInfo.city, areaInfo.dist);

                            }, userId, year, month, areaInfo.prov, areaInfo.city, areaInfo.dist);
                        }
                    })(n, retAreaInfo[n]));
                }
                // 串行处理
                async.series(subAsync, function(error, results){

                    var retLst = [];
                    if(results && results.length>0) {
                        for(var i=0;i<results.length;i++) {
                            var info = results[i];
                            if(info && info.updCnt>0) {// 只返回有数据的
                                retLst.push(info);
                            }
                        }
                    }

                    return callback(error, {dist:retLst});
                });

            } else {
                console.log('callFuncUtil.js [refreshSaleRankInfo] : 未获取到合伙人地区信息 ');
                return callback(null, null);
            }
        });
    };

    //------------------------------------------------------------------
    // redis优惠券key前缀
    callFuncUtil.getCouponKeyPrefix = function(use) {
        use = Number(use||'0')||0;

        var keyPrefix = '';
        if(use>0) {
            keyPrefix += ALL_COUPON_PREFIX+use+'_';
            //if(use==20) {
            //    keyPrefix += '4_';
            //} else if(use==30) {
            //    keyPrefix += '4_';
            //} else if(use==31) {
            //    keyPrefix += '9_';
            //} else if(use==32) {
            //    keyPrefix += '1010_';
            //} else {
            //    keyPrefix += '0_';// 不限limit
            //}
        }

        return keyPrefix;
    };


    //------------------------------------------------------------------
    // 测试用
    callFuncUtil.tmpTst = function(use, callback){
        //var rds = CouponRedisCache;
        //if(use==30) {
        //    rds = Coupon2RedisCache;
        //} else if(use==31) {
        //    rds = Coupon3RedisCache;
        //}
        //// 随机获取
        //rds.randomkey(function(err, retKey){
        //    if(retKey && retKey.length>0) {
        //        // 删除已获取到的
        //        rds.del(retKey, function(err2, ret2){
        //            if(err2) {
        //                return callback(err2, null);
        //            }
        //
        //            rds.del(retKey, function(err3, ret3){
        //                if(err3) {
        //                    return callback(err3, null);
        //                }
        //
        //                return callback(null, retKey);
        //            });
        //        });
        //    } else {
        //        return callback(err, null);
        //    }
        //});
        return callback(null, null);
    };

    //-----------------------------------------------------------------
    /**2017-10-20
     * 更新本地DB的物流信息--李琦
     * updExpTrackDataService方法
     * 查询本地未签收的物流订单号/定时更新
     * force: 1强制更新; 0只更新如下物流（0未知，1揽件中，2在途中，3派件中）
     */
    callFuncUtil.updExpTrackDataService = function(force, callback){
        (new ItbExpTrackInfoModel).getTodoExpTrackItems(function(err,ret){//查询本地未签收的订单
            if(err){
                return callback(err, null);
            }
            if(ret && ret.length>0){
                var subAsync = [];
                for(var i=0;i<ret.length;i++){
                    var expState = Number(ret[i].state||'0')||0;

                    if(!force && expState!=0 && expState!=1 && expState!=2 && expState!=3) {
                        console.log('Skip Chk ExpInfo: '+ret[i].tracking_no);
                        continue;
                    }
                    console.log('Chk ExpInfo: '+ret[i].tracking_no);

                    subAsync.push((function(idx,info){//将ret[i]赋值给info、定义方式
                        return function(subCallback){
                            callFuncUtil.funExpTrackData(info,subCallback );
                        }
                    })(i,ret[i]));
                }
                // 串行处理
                async.series(subAsync, function(error, results){
                    if(error){
                        console.log(error);
                        return callback(error,null);
                    }
                    var cnt = results.length||0;
                    var okCnt = 0;
                    for(var n=0;n<results.length;n++) {
                        if(results[n].OK==1) {
                            okCnt++;
                        }
                    }
                    return callback(null, {cnt:cnt,ok:okCnt});
                });
            } else {
                return callback(null, {cnt:0, ok:0});
            }
        });
    };


    /**  @author--李琦
     * funExpTrackData方法 更新itb_exp_track_info中data和state字段
     * @param obj// 单个对象
     * @param callback 回调函数 返回成功/失败
     * obj.trade_type//物流订单类型 商品订单/发票订单
     * obj.order_id;//订单ID
     * obj.to_addr_id;//收货地址
     * obj.user_id;//用户ID
     */
    callFuncUtil.funExpTrackData = function(obj,callback){
        var appCode = 'e8feb2acc90048e792e951eaff2dd9cf';//阿里的appCode
        var number = obj.tracking_no;//订单号
        var type = obj.cd;//获取物流公司类型 如圆通/sto
        var ex_id = obj.ex_id;//获取物流主键ID

        if(number!=null){//判断number和type不为空
            var apiUrl = "http://jisukdcx.market.alicloudapi.com/express/query";
            if(type==null){//判断type=null 则赋值auto
                type = 'auto';
            }
            var options = {
                url: apiUrl + '?type='+type+'&number='+number+'',
                headers: {
                    'Authorization': 'APPCODE '+appCode
                }
            };
            //请求阿里api获取物流信息
            request(options, function (error, response, body) {//发送请求
                if (!error && response.statusCode == 200) {
                    var info = JSON.parse(body)||{};
                    if(info){//判断返回值 不为空
                        var status = info.status;
                        var retData = (body||'').replace(/&nbsp;/g," ");// 特殊处理
                        if(status==0){//如果status=0表示查询物流成功 0成功 失败
                            var deliverState = info.result.deliverystatus;
                            var state = 0;
                            if(deliverState){
                                state = Number(deliverState)+1;//转换和本地DB数据匹配
                            }
                            if(state!=null && info!=null){//判断不为空
                                if(ex_id){//判断ex_id=null则重新插入/!=null则修改
                                    (new ItbExpTrackInfoModel).updExpTrackInfoData(ex_id,state,retData,'API',function(error,result){
                                        return callback(null,{No:number,OK:1});
                                    });
                                }else{//不是则插入DB一条新的数据
                                    obj.update_by='API';
                                    (new ItbExpTrackInfoModel).insertItbExpTrackInfo(obj,state,retData,function(error,result){
                                        return callback(null,{No:number,OK:1});
                                    });
                                }
                            }else {
                                return callback(null,{No:number,OK:0});
                            }
                        }else {
                            return callback(null,{No:number,OK:0});
                        }
                    }else {
                        return callback(null,{No:number,OK:0});
                    }
                } else {
                    return callback(null,{No:number,OK:0});
                }
            });
        } else {
            return callback(null,{No:'param null',OK:0});
        }
    };


    //------------------------------------------------------------------
    return callFuncUtil;
})();


//------------------------------------------------------------------
module.exports = callFuncUtil;

